package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.web.CategoryVo;
import com.atguigu.gmall.feign.product.CategoryFeignClient;
import feign.Request;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 首页
 */
@Controller
public class IndexController {


    @Autowired
    CategoryFeignClient categoryFeignClient;
    /**
     * 首页
     * @return
     */
    @GetMapping({"/","/index.html"})
    public String indexpage(Model model){


        //RPC 商品服务，得到结果
//        String tree = categoryFeignClient.getCategoryTree();
        //精确控制远程超时
//        Request.Options options = new Request.Options(1, TimeUnit.SECONDS,
//                1,TimeUnit.SECONDS,false);
//
//        Result<List<CategoryVo>> categorys = categoryFeignClient.getCategorys(options);


        Result<List<CategoryVo>> categorys = categoryFeignClient.getCategorys();
        List<CategoryVo> data = categorys.getData();

        model.addAttribute("list",data);
        return "index/index";
    }


}
